<?php
$records = $this->records;

if (count($records) > 0) {
    $thisCat = $records;
    $catID = $thisCat['category_id'];
?>
<h1>
    <?php
        $allCategory = $this->allCategory;
        @$allParent = $allCategory[$catID]['all_parent'];
        $arrParent = explode(',', $allParent);
        $first = true;
        $cat_id = 0;
        foreach($arrParent as $parent_id):
            @$parent = $allCategory[$parent_id];
            if ($parent['left'] != 1) {
        ?>
            <a href="<?php echo BASE_URL?>/category/detail/?id=<?php echo $parent['category_id'];?>"><?php echo $parent['admin_title']?></a> &raquo;
        <?php
            }
        endforeach;

    ?>
    <span class="pink">
        <?php echo $thisCat['admin_title']?>  
    </span>
    &raquo;
    <span class="pink">
        Category Information
    </span>
</h1>

<table class="border" width="70%">
    <thead>
        <tr>
            <td colspan="2">Basic information</td>
        </tr>
    </thead>
    <tbody>
<?php
if( $thisCat['level'] <= 1) {
?>
        <tr>
            <td width="150">Description</td>
            <td>
            <?php echo $thisCat['description']?>
            </td>
        </tr>
        <tr>
            <td width="150">Photo</td>
            <td>
            <?php 
            $image = @$thisCat['main_image'];
            //echo stripos($image, 'http');
            
            if (stripos($image, 'http') === false) {
                $image = BASE_PATH . $image;
            } else {
                //echo $image = BASE_PATH . $image;
                // do nothing
            }
            
            echo $thisCat['main_image'];
            ?>
            <img src="<?php echo $image?>" style="max-width:500px">
            </td>
        </tr>
        <tr>
            <td width="150">Photo link</td>
            <td>
            <?php
            echo $thisCat['photo_link'];
            ?>
            </td>
        </tr>
        <tr>
            <td width="150">Embed youtube video</td>
            <td>
            <?php
            echo $thisCat['embed_youtube'];
            ?>
            </td>
        </tr>
<?php
} // if level = 1
?>
        <tr>
            <td width="150">Title</td>
            <td>
            <?php echo $thisCat['admin_title']?>
            </td>
        </tr>
        <tr>
            <td width="150">Featured Category</td>
            <td>
            <?php
            $FeaturedCategory = array('NO', 'YES');
            echo @$FeaturedCategory[$thisCat['FeaturedCategory']];
            ?>
            </td>
        </tr>
    </tbody>
</table>

<?php
if( $thisCat['level'] <= 1) {
    $childs = array();
    @$childs =  $thisCat['children'];
?>
<table class="border" width="70%">
    <thead>
        <tr>
            <td colspan="2">Subcategories: <?php echo count($childs)?></td>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>
                <ol>
            <?php
            if (count($childs) > 0) {
                $allCategory = $this->allCategory;
                foreach ($childs as $child):
                    $cat = $allCategory[$child];
                ?>
                    <li class="normal">
                        <a href="<?php echo BASE_URL?>/category/detail/?id=<?php echo $cat['category_id']?>"><?php echo $cat['admin_title']?></a>
                    </li>
                <?
                endforeach;
            }// childs
            ?>
                </ol>
            </td>
        </tr>
    </tbody>
</table>

<a href="<?php echo BASE_URL?>/category/edit/id/<?php echo $thisCat['category_id']?>">Update Category</a>
- 
<a href="<?php echo BASE_URL?>/category/add/?pa_id=<?php echo $thisCat['category_id']?>">Add Sub Categories</a>
<?
} // if level 1
else { // level > 1
?>
    <a href="<?php echo BASE_URL?>/category/edit/id/<?php echo $thisCat['category_id']?>">Update Category</a>
<?php
} // level > 1
} // if has data
?>